//
// Created by Administrator on 2021/10/20.
//
#include "node.h"
#include "linkedQueue.h"
#include "iostream"
using namespace std;

LinkedQueue::LinkedQueue() {
    this->ptrToFront = nullptr;
    this->ptrToBack = nullptr;
    this->count = 0;
}

LinkedQueue::~LinkedQueue() {}

void LinkedQueue::push(const int value) {
    if (this->ptrToBack == nullptr) {
        this->ptrToBack = new Node(value, nullptr);
        this->ptrToFront = this->ptrToBack;
    } else {
        this->ptrToBack->setNext(new Node(value, nullptr));
        this->ptrToBack = this->ptrToBack->getNext();
    }
    this->count++;
}

void LinkedQueue::pop() {
    if (this->ptrToFront == nullptr)
        return;
    Node *temp = this->ptrToFront;
    this->ptrToFront = this->ptrToFront->getNext();
    delete temp;
    this->count--;
}

bool LinkedQueue::empty() const {
    return this->count == 0;
}

int LinkedQueue::back() const {
    return this->ptrToBack->getData();
}

int LinkedQueue::front() const {
    return this->ptrToFront->getData();
}

size_t LinkedQueue::size() const {
    return this->count;
}

